package structs

import (
	"github.com/gin-gonic/gin"
	"strconv"
	"woo-server/models/db"
)

type Common struct {
	Context   *gin.Context `gorm:"-"`
	Claim     *AuthClaim   `gorm:"-"`
	Operation string       `gorm:"-"`
	Ip        string       `gorm:"-"`
}

// 下拉选项结构体
type Options struct {
	Value    uint64
	Label    string
	ChildRen []Options
}

// 多选框结构体
type OPTIONS struct {
	Select        []Options
	SelectOptions interface{}
}

// 获取配合结构
type CFConfig struct {
	Column []ColumnCommon
	Forms  []FormsCommon
}

// 共用列表
type ColumnCommon struct {
	Title     string
	DataIndex string
}

// 共用表单
type FormsCommon struct {
	Key     string
	Label   string
	Type    string
	Options interface{}
}

// 菜单字段表
type AdminMenus struct {
	Common
	AdminMenuId uint64 `gorm:"primary_key;AUTO_INCREMENT;column:admin_menu_id;"` // 自增主键
	ParentId    uint64 `gorm:"column:parent_id;size:255;"`
	Name        string `gorm:"column:name;size:255;"`
	IsHidden    uint   `gorm:"column:is_hidden;size:255;"` //
	Icon        string `gorm:"column:icon;size:50;"`       //
	Sort        uint   `gorm:"column:sort;size:255;"`
	Url         string `gorm:"column:url;size:255;"`     //
	WebUrl      string `gorm:"column:web_url;size:255;"` //
	ChildRen    interface{}
	Select      []uint64
	Status      uint `gorm:"column:status;"` //状态
	db.Basics
}

// 菜单字段表
type ProductCategory struct {
	*Common    `gorm:"-" json:"-"`
	CategoryId uint64 `gorm:"primary_key;AUTO_INCREMENT;column:category_id;"` // 自增主键
	ParentId   uint64 `gorm:"column:parent_id;size:255;"`
	Name       string `gorm:"column:name;size:255;"`
	ImageId    uint   `gorm:"column:image_id;size:255;"` //
	Sort       uint   `gorm:"column:sort;size:255;"`
	ChildRen   interface{}
	Select     []uint64
	db.Basics
}

// 权限表
type ROLE struct {
	Common      `gorm:"-" json:"-"`
	AdminRoleId uint64       `gorm:"primary_key;AUTO_INCREMENT;column:admin_role_id;"` // 自增主键
	Name        string       `gorm:"column:name;size:50;"`                             //
	AdminMenuId string       `gorm:"column:admin_menu_id;"`
	Describe    string       `gorm:"column:describe;size:150;"`
	AdminMenus  []AdminMenus `gorm:"foreignKey:AdminMenuId"`
	db.Basics
}

type AuthClaim struct {
	AdminMenu string
	UserId    uint64 //用户id
	Name      string
	Avatar    string
	RoleId    uint64
}

func SetInt(str string) int {
	intResult, _ := strconv.Atoi(str)
	return intResult
}

func SetFloat(str string, bitSize int) float64 {
	intResult, _ := strconv.ParseFloat(str, bitSize)
	return intResult
}
